﻿using EasyRunner.EasyCore;
using EasyTask.EasyHelper;
using log4net.Config;
using System;
using System.IO;
using Topshelf;

namespace EasyTask
{
    class Program
    {
        static  void Main(string[] args)
        {
            XmlConfigurator.ConfigureAndWatch(new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "log4net.config"));

            //安装命令：(管理员运行)
            //进入EasyTask.exe 所在目录
            //输入:EasyTask.exe install
            HostFactory.Run(x =>
            {
                x.UseLog4Net();
                x.Service<ServiceRunner>(s =>
                {
                    s.ConstructUsing(name => new ServiceRunner());
                    s.WhenStarted(async tc => await tc.Start());
                    s.WhenStopped(async tc => await tc.Stop());
                });
                x.RunAsLocalSystem();
                x.StartAutomatically();
                x.SetDisplayName(Config.GetValue("EasyTaskDisplayName"));
                x.SetDescription(Config.GetValue("EasyTaskDescription"));
                x.SetServiceName(Config.GetValue("EasyTaskServiceName"));
            });
            Console.WriteLine($@"
            显示名称:{Config.GetValue("EasyTaskDisplayName")}
            服务描述:{Config.GetValue("EasyTaskDescription")}
            服务名称:{Config.GetValue("EasyTaskServiceName")}
            请输入:net start EasyTask 启动服务。");
        }
    }
}
